package de.hska.kundenverwaltung.db;

import java.io.Serializable;

import javax.persistence.Column;
import javax.persistence.Embeddable;


@Embeddable
public class Adresse implements Serializable {
	private static final long serialVersionUID = 4618817696314640065L;

	@Column(nullable=false)
	private int plz;

	@Column(length=32, nullable=false)
	private String ort;

	@Column(length=32, nullable=false)
	private String strasse;

	@Column(length=4)
	private String hausnr;

	public Adresse() {
		super();
	}

	public Adresse(int plz, String ort, String strasse, String hausnr) {
		super();
		this.plz = plz;
		this.ort = ort;
		this.strasse = strasse;
		this.hausnr = hausnr;
	}

	public int getPlz() {
		return plz;
	}
	public void setPlz(int plz) {
		this.plz = plz;
	}

	public String getOrt() {
		return ort;
	}
	public void setOrt(String ort) {
		this.ort = ort;
	}

	public String getStrasse() {
		return strasse;
	}

	public void setStrasse(String strasse) {
		this.strasse = strasse;
	}

	public String getHausnr() {
		return hausnr;
	}
	public void setHausnr(String hausnr) {
		this.hausnr = hausnr;
	}

	@Override
	public String toString() {
		return "{plz=" + plz + ", ort=" + ort + ", strasse=" + strasse + ", hausnr=" + hausnr + '}';
	}

	@Override
	public int hashCode() {
		final int PRIME = 31;
		int result = 1;
		result = PRIME * result + ((hausnr == null) ? 0 : hausnr.hashCode());
		result = PRIME * result + ((ort == null) ? 0 : ort.hashCode());
		result = PRIME * result + plz;
		result = PRIME * result + ((strasse == null) ? 0 : strasse.hashCode());
		return result;
	}

	@Override
	public boolean equals(Object obj) {
		if (this == obj)
			return true;
		if (obj == null)
			return false;
		if (getClass() != obj.getClass())
			return false;
		final Adresse other = (Adresse) obj;
		if (hausnr == null) {
			if (other.hausnr != null)
				return false;
		} else if (!hausnr.equals(other.hausnr))
			return false;
		if (ort == null) {
			if (other.ort != null)
				return false;
		} else if (!ort.equals(other.ort))
			return false;
		if (plz != other.plz)
			return false;
		if (strasse == null) {
			if (other.strasse != null)
				return false;
		} else if (!strasse.equals(other.strasse))
			return false;
		return true;
	}

}
